package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.IApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ApArticleConfigService extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements IApArticleConfigService {
    /**
     * 接收自媒体端的消息,修改文章配置表的文章上下架状态
     * @param map
     */
    @Override
    public void downOrUp(Map map) {
        //获取请求参数中的articleId和enable值
        Long articleId = (Long) map.get("articleId");
        Object enable = map.get("enable");
        //自媒体端和app端文章的上下架正好是相反的,先对enable的值进行一个取反操作
        Boolean isDown =true;
        if (enable.equals(1)){
            //enable=1,表示自媒体端文章是上架状态,则需要把isDown的值改为false
            isDown = false;
        }
        //调用方法进行修改操作
        this.update(Wrappers.<ApArticleConfig>lambdaUpdate()
                .eq(ApArticleConfig::getArticleId,articleId)
                .set(ApArticleConfig::getIsDown,isDown));
    }
}
